package com.itheima.test;

import java.util.Random;

public class test3 {
    public static void main(String[] args) {
        //键盘输入任意字符串，打乱其中内容


        //1.键盘输入
        String str = "abcdefg";

        //2.打乱其中的内容
        char[] arr = str.toCharArray();//编程字符数组

        //3.打乱字符数组
        //从0索引开始，跟一个随机索引进行交换
        for (int i = 0; i < arr.length; i++) {
            Random r = new Random();
            int randomIndex = r.nextInt(arr.length);
            char temp = arr[i];
            arr[i] = arr[randomIndex];
            arr[randomIndex] = temp;
        }

        //4.把数组再变回字符串
        String result = new String(arr);

        System.out.println(result);
    }
}
